direct = [[1,0],[0, 1], [-1, 0], [0, -1]]
first = set()
second = set()

def dfs(grid, visited, x, y, fs):
    if visited[y][x]:
        return
    
    visited[y][x] = True
    fs.add((y, x))
    
    for i, j in direct:
        next_x = x + i
        next_y = y + j
        if (
            0<= next_x < len(grid[0]) 
            and 0<=next_y<len(grid) 
            and grid[next_y][next_x]>=grid[y][x]
            ):
            dfs(grid, visited, next_x, next_y, fs)

def main():
    N,M = map(int, input().split())
    
    grid = []
    for i in range(N):
        grid.append(list(map(int, input().split())))
    
    
    global first, second
    
    visited = [[False]*M for i in range(N)]
    for i in range(N):
        dfs(grid, visited, 0, i, first)
    for i in range(M):
        dfs(grid, visited, i, 0, first)
        
    visited = [[False]*M for i in range(N)]
    for i in range(N):
        dfs(grid, visited, M-1, i, second)
    for i in range(M):
        dfs(grid, visited, i, N-1, second)
    
    res = first & second
    for i, j in res:
        print(f"{i} {j}")
    
main()